import { ColumnsType } from 'ant-design-vue/lib/table'

// 列表字段
export const columnsList: ColumnsType = [
  {
    title: '字段名称',
    dataIndex: 'fieldName',
    ellipsis: { showTitle: true }
  },
  {
    title: '字段类型',
    dataIndex: 'fieldType'
  },
  {
    title: '字段编码',
    dataIndex: 'fieldCode'
  },
  {
    title: '操作',
    dataIndex: 'edit',
    width: 340,
    align: 'left'
  }
]
// 1: 单行文本
// 2: 多行文本
// 3: 数值
// 4: 单选框
// 5: 复选框
// 6: 下拉框
// 7: 日期时间
// 8: 说明文字
// 9: 文件上传
// 10: 循环事件
// 11: 级联选择
export enum fieldType {
  singleLineText = 1,
  multiLineText = 2,
  number = 3,
  radio = 4,
  checkbox = 5,
  select = 6,
  dateTime = 7,
  text = 8,
  upload = 9,
  cycleEvent = 10,
  cascader = 11,
  fixedCombination = 12,
  treeSelect = 13,
  packing = 14
}
export const fieldTypeOpstion = [
  {
    label: '单行文本',
    code: 'input',
    value: fieldType.singleLineText,
    type: 'basicComponents'
  },
  {
    label: '多行文本',
    code: 'textarea',
    value: fieldType.multiLineText,
    type: 'basicComponents'
  },
  {
    label: '数值',
    code: 'number',
    value: fieldType.number,
    type: 'basicComponents'
  },
  {
    label: '单选框',
    code: 'radio',
    value: fieldType.radio,
    type: 'selectComponents'
  },
  {
    label: '复选框',
    code: 'checkbox',
    value: fieldType.checkbox,
    type: 'selectComponents'
  },
  {
    label: '下拉框',
    code: 'select',
    value: fieldType.select,
    type: 'selectComponents'
  },
  {
    label: '日期时间',
    code: 'date',
    value: fieldType.dateTime,
    type: 'selectComponents'
  },
  {
    label: '说明文字',
    code: 'text',
    value: fieldType.text,
    type: 'basicComponents'
  },
  {
    label: '文件上传',
    code: 'upload',
    value: fieldType.upload,
    type: 'selectComponents'
  },
  {
    label: '级联选择',
    code: 'cascader',
    value: fieldType.cascader,
    type: 'selectComponents'
  },
  {
    label: '固定组合',
    code: 'fixedCombination',
    value: fieldType.fixedCombination,
    type: 'layoutComponents'
  },
  {
    label: '树选择',
    code: 'treeSelect',
    value: fieldType.treeSelect,
    type: 'selectComponents'
  },
  {
    label: '包装规格',
    code: 'packing',
    value: fieldType.packing,
    type: 'selectComponents'
  }
]

export const getFieldType = (value) => {
  const currItem = fieldTypeOpstion.find((item) => item.value === value)
  return currItem ? currItem.label : ''
}

export interface IFieldForm {
  fieldName: string
  fieldType: number
  fieldCode: string
  promptInfo: string
  placeholder: string
  fieldAttr: number
  defaultValue: any
  optionList: Array<any>
  hidePromptFlag: number
  hideFieldNameFlag: number
  requiredFlag: number
  formatCheck: number
  lengthLimit: number
  minValueLimit?: number
  maxValueLimit?: number
  numericFormat?: number
  decimalPoint?: number
  optionSource?: number
  multipleFlag?: number
  defaultValueType?: number
  dateType?: string
  dateFormat?: string
  remoteConfig?: any
}

export const fieldFormSource = (): IFieldForm => {
  return {
    fieldName: '',
    fieldType: 1,
    fieldCode: '',
    promptInfo: '',
    placeholder: '',
    fieldAttr: 1,
    defaultValue: '',
    optionList: [
      { label: '选项1', value: '1' },
      { label: '选项2', value: '2' }
    ],
    hidePromptFlag: 0,
    hideFieldNameFlag: 0,
    requiredFlag: 1,
    formatCheck: 1,
    lengthLimit: 200,
    minValueLimit: 0,
    maxValueLimit: 200,
    numericFormat: 1,
    decimalPoint: 0,
    optionSource: 1,
    multipleFlag: 0,
    defaultValueType: 1,
    dateType: '',
    dateFormat: '',
    remoteConfig: {
      url: undefined,
      valueKey: undefined,
      lableKey: undefined,
      children: undefined
    }
  }
}

/**
 * 固定组合字段编码
 */
export enum fixedCombinationFieldCode {
  piInfo = 'piInfo',
  sponsorInfo = 'sponsorInfo',
  croInfo = 'croInfo',
  smoInfo = 'smoInfo',
  thirdCheckInfo = 'thirdCheckInfo'
}

/**
 * 固定组合字段的字段编码
 */
export const fixedCombinationCode = {
  piInfo: {
    piMajor: 'piMajor',
    piName: 'piName',
    piTitle: 'piTitle'
  },
  sponsorInfo: {
    sponsorOrg: 'sponsorOrg',
    sponsorContact: 'sponsorContact',
    sponsorPhone: 'sponsorPhone'
  },
  croInfo: {
    croOrg: 'croOrg',
    croContact: 'croContact',
    croPhone: 'croPhone'
  },
  smoInfo: {
    smoOrg: 'smoOrg',
    smoContact: 'smoContact',
    smoPhone: 'smoPhone'
  },
  thirdCheckInfo: {
    thirdCheckOrg: 'thirdCheckOrg',
    thirdCheckContact: 'thirdCheckContact',
    thirdCheckPhone: 'thirdCheckPhone'
  }
}
